package projectx.web.base;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import projectx.core.base.ProjectXMessage;
import projectx.util.CollectionUtil;

public abstract class ProjectXMultiSelectListForm extends ProjectXListForm {

	private String[] _selectedRows;

	protected void validate(ActionErrors errors, ActionMapping mapping,
			HttpServletRequest request) {
		checkSelectedRow(errors);

		if (errors.size() > 0) {
			initViewData(request);
		}
	}

	protected void checkSelectedRow(ActionErrors errors) {
		if (CollectionUtil.isEmpty(_selectedRows)) {
			addError(errors, new ProjectXMessage("E0313"));
		}
	}

	protected abstract void initViewData(HttpServletRequest request);

	public String[] getSelectedRows() {
		return _selectedRows;
	}

	public void setSelectedRows(String[] selectedRows) {
		_selectedRows = selectedRows;
	}
}